<?php
	//Xay dung tim kiem
	$ssFilter 		= $this->arrParam['ssFilter'];
	$page = '';
	if(isset($this->arrParam['page'])){
		$page = '/page/' . $this->arrParam['page'];
	}
	$id_kh = '';
	if(!empty($this->arrParam['id_kh'])){
		$id_kh = '/id_kh/' . $this->arrParam['id_kh'];
	}
	
	$action_link 		= $this->baseUrl($this->currentController . '/filter/type/order' . $id_kh);
	$lblGiatri 			= $this->cmsLinkSort('Giá trị', 'hd.hd_thanhtien', $ssFilter, $this->imgUrl . '/admin',$action_link);
	$lblSotienno 		= $this->cmsLinkSort('Còn nợ', 'hd.hd_sotienno', $ssFilter, $this->imgUrl . '/admin',$action_link);
	$lblNgayky 			= $this->cmsLinkSort('Ngày ký', 'hd.ngayky', $ssFilter, $this->imgUrl . '/admin',$action_link);
	$lblKhachhangName	= $this->cmsLinkSort('Tên khách hàng', 'hd.khachhang_name', $ssFilter, $this->imgUrl . '/admin',$action_link);
	$lblNhanvienName	= $this->cmsLinkSort('Người quản lý', 'nhanvien_name',  $ssFilter, $this->imgUrl. '/admin', $action_link);	
	$lblLophoc			= $this->cmsLinkSort('Lớp học', 'hd.id_lophoc',  $ssFilter, $this->imgUrl. '/admin', $action_link);	
	
	$keywords = $this->formText('keywords',$ssFilter['keywords'],array('class'=>'txtshort txtsearch'));
	
	//---------------------GROUP SELECTBOX --------------------//
	$this->slbKhoahoc[0] = '- Chọn khóa học -';
	$linkSlbKhoahoc = $this->baseUrl($this->currentController . '/filter/type/id_khoahoc' . $id_kh);
	$selectKhoahoc = $this->formSelect('id_khoahoc', $ssFilter['id_khoahoc'], array('style'=>'width:120px;','onchange'=>"OnSubmitForm('" .$linkSlbKhoahoc ."')"), $this->slbKhoahoc);

	$this->slbLopHoc[0] = '- Chọn lớp học -';
	$linkSlbLopHoc = $this->baseUrl($this->currentController . '/filter/type/id_lophoc' . $id_kh);
	$selectLopHoc = $this->formSelect('id_lophoc', $ssFilter['id_lophoc'], array('style'=>'min-width:100px;','onchange'=>"OnSubmitForm('" .$linkSlbLopHoc ."')"), $this->slbLopHoc);
	
	
	$linkSlbPhongban 	= $this->baseUrl($this->currentController . '/filter/type/id_phongban/' . $this->arrParam['tn']);
	$selectPhongban 	= $this->cmsSelect('id_phongban', $ssFilter['id_phongban'], $this->slbPhongban, array('onchange'=>"OnSubmitForm('" .$linkSlbPhongban ."')"));
	
	$linkSlbNhanvien 	= $this->baseUrl($this->currentController . '/filter/type/id_nhanvien/' . $this->arrParam['tn']);
	$selectNhanvien 	= $this->formSelect('id_nhanvien', $ssFilter['id_nhanvien'], array('onchange'=>"OnSubmitForm('" .$linkSlbNhanvien ."')"), $this->slbNhanvien);
	
	
	
	$linkSearch = $this->baseUrl($this->currentController . '/filter/type/search/key/1' . $id_kh);
	$btnSearch = $this->formButton('search-now','Tìm', array('class' => 'btnsearch', 'onclick'=>"OnSubmitForm('" .$linkSearch . "')"));
	
	$linkResetSearch = $this->baseUrl($this->currentController . '/filter/type/search/key/0' . $id_kh);
	$btnResetSearch = $this->formButton('clear-keywords','Xóa',array('class' => 'btnsearch', 'onclick'=>"OnSubmitForm('" .$linkResetSearch ."')"));
	
	$strSearch = $keywords . ' ' . $btnSearch . ' ' . $btnResetSearch;

	$linkBlocks = $this->baseUrl($this->currentController . '/filter/type/blocks');
	$slbBlocks = array(
			'0' => '- Lựa chọn -',
			'nohocphi'=> 'Còn nợ học phí',
			'chuavaolop'=> 'Chưa xếp vào lớp',
	);
	$selectBlocks = $this->formSelect('blocks',$ssFilter['blocks'],array('style'=>'width:110px;', 'onchange'=>"OnSubmitForm('" .$linkBlocks ."')"),$slbBlocks);
	
	$strSearchRight = $selectPhongban . ' ' . $selectNhanvien.' '.$selectKhoahoc . ' ' . $selectLopHoc . ' ' . $selectBlocks;
?>

<div class="left_content">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/left.php');?>
</div>

<div class="right_content">
	<div class="appContent">
	
	<form action="" method="post" name="appForm">
		<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
		<?php
			if($this->arrParam['save'] == 'ok'){
				echo '<div class="thongbaoThanhCong goc5">Xử lý dữ liệu thành công</div>';
			} 
		?>
		<div class="formList goc5">
			<div class="appTop goct5">
				<div class="block_filter">
					<div class="fl">
						<div class="listSearch">
							<?php echo $strSearch; ?>
							<div class="clr"></div>			
						</div>
					</div>
					<div class="fr">
						<div class="listSelect">
							<?php echo $strSearchRight; ?>
						</div>
					</div>
					<div class="clr"></div>
				</div>
			</div>
			<div class="appBody">
				<table class="tblList">
					<tr>
						<th width="20"><input type="checkbox" id="checkall" class="checkbox" onclick="checkedAll();" /></th>
						<th>Mã hợp đồng</th>
						<th>Tên khách hàng</th>
						<th width="70">Giá trị <span class="note">(VNĐ)</span></th>
						<th width="75">Còn nợ <span class="note">(VNĐ)</span></th>
						<th width="75"><?php echo $lblNgayky?></th>
						<th><?php echo $lblLophoc;?></th>
						<th width="60">Thao tác</th>
					</tr>
					<?php 
						foreach ($this->Items as $key => $val) {
							$id 			= $val['id'];
							$code 			= strtoupper($val['khachhang_code']) . '-' . $val['id'];
							$khachhang_name = $val['khachhang_name'];
							$hd_thanhtien	= $val['hd_thanhtien'];
							$hd_sotienno	= $val['hd_sotienno'];
							if($val['hd_sotienno'] > 0) {
								$hd_sotienno = '<span class="red auto_numberic">' . $val['hd_sotienno'] . '</span>';
							}
							$ngayky			= $val['ngayky'];
							$nhanvien_name 	= $val['nhanvien_name'];
							if(!empty($val['nhanvien_alias'])) {
								$nhanvien_name = $val['nhanvien_name'] . ' (' . $val['nhanvien_alias'] . ')';
							}
							$lophoc_name 	= $val['lophoc_name'];
							
							$linkInfo		= $this->baseUrl($this->currentController . '/info' . '/id_kh/' . $val['id_kh'] . '/id/' . $id . $page);
							$btnInfo		= $this->cmsIconButton('Xem thông tin', $this->imgUrl . '/admin/icon_info.png', $linkInfo);
							
							$linkEdit		= $this->baseUrl($this->currentController . '/edit/id/' . $id . $page);
							$btnEdit		= $this->cmsIconButton('Sửa', $this->imgUrl . '/admin/icon_edit.png', $linkEdit);
							
							$linkDelete		= $this->baseUrl($this->currentController . '/delete/id/' . $id . $page);
							$btnDelete		= $this->cmsIconButton('Xóa', $this->imgUrl . '/admin/icon_del.png', $linkDelete);
							
							$strIconButton 	= $btnEdit . $btnDelete;
								
							$cid 			= $this->formCheckbox('cid[]',$val['id']);
					?>
						<tr <?php if (($id % 2) != 0) echo "class='row1'"; ?>>
							<td align="center"><?php echo $cid; ?></td>
							<td align="center"><?php echo $code; ?></td>
							<td align="left"><?php echo $khachhang_name; ?> <p class="smallsub">Người quản lý: <?php echo $nhanvien_name;?></p></td>
							<td align="right"><span class="auto_numberic"><?php echo $hd_thanhtien; ?></span></td>
							<td align="right"><?php echo $hd_sotienno; ?></td>
							<td align="center"><?php echo $ngayky; ?></td>
							<td align="center"><?php echo $lophoc_name; ?></td>
							<td align="center"><?php echo $strIconButton; ?></td>
						</tr>
					<?php
						}
					?>					
				</table>
			</div>
			<div class="appBottom">
				<div class="pagination">
					<?php
						$currentUrl = $this->baseUrl($this->currentController . '/index');
						echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml', array('currentUrl'=>$currentUrl)); 
					?>
				</div>
			</div>
		</div>
	</form>
	</div>
</div>
<div class="clr"></div>	
